package developerworks.jetty6;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.mortbay.util.ajax.Continuation;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;

import java.util.Hashtable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class User extends CrudMessage {
	public String name;
	public String id;
	public String page;
	public String session_id;
	public String location;
	public String call_id;
	public Long create_time;

	private HttpSession session;
	private Pattern pattern = Pattern.compile("https?://(?:www\\.)?([^/]*)([^#\\?]*)");
	
	

	
	public User( HttpServletRequest req, HttpSession s) {
		super();
		page = req.getHeader("Referer");
		name = req.getParameter("user[name]");
		call_id = req.getParameter("user[call_id]");
		id = req.getParameter("user[active_user_id]");
		session_id = s.getId();
		create_time = s.getCreationTime();
	}
	
	
	public JSONObject toJson() throws JSONException {
		JSONObject jsonObj = new JSONObject();
		jsonObj.put("call_id", call_id);
		jsonObj.put("name", name);
		jsonObj.put("page", page);
		jsonObj.put("time", create_time);
	    return jsonObj;
	}
	public void update(String n){
		name=n;
	}
	public String toString(){
		return "USER:"+name;
	}
	//maybe this type of nested adding should be done in the other thread
	

	
	public void updateName(String n){
		name = n;
	}

}
